home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5474 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.deltanet.com!usenet
  2. From: kkhan@deltanet.com (AK)
  3. Newsgroups: comp.lang.c++
  4. Subject: Help a newbie with a problem....
  5. Date: Sun, 04 Feb 1996 21:44:32 GMT
  6. Organization: Delta Internet Services, Anaheim, CA
  7. Message-ID: <311527bc.180318@news.deltanet.com>
  8. NNTP-Posting-Host: rvr0145.deltanet.com
  9. X-Newsreader: Forte Agent .99c/16.141
  10.  
  11. Ok I have no clue as to what is wrong with this statement, I have
  12. tried various forms with no success. The statement is supposed to give
  13. me a factorial result with this formula :  (n - r + 1) / r.
  14.  
  15. Here is my code:
  16.  int num,                         // Number of balls in the bin.
  17.     sel,                         // Number of balls selected.
  18.     fact;                        // Sets the factorial
  19.     long combo;                      // The odds of winning lottery.
  20.  
  21.     // Prompt for user to enter the number of balls total and number
  22.     // selected.
  23.     cout << endl << "Enter the number of balls in bin: ";
  24.     cin >> num;
  25.     cout << endl << "Enter the number of balls selected: ";
  26.     cin >> sel;
  27.  
  28.     // A loop used to calculate the odds with the values given by the
  29. user.
  30.        for ( int r = 1; r <= sel; r++)
  31.        {
  32.       combo = 1;
  33.       for ( int fact = ( (num - r + 1) / r ); fact <= r; fact++)
  34.       { combo *= fact; }
  35.  
  36.        }
  37.     cout << endl << "Odds of winning: 1 in " << combo;
  38. }
  39.  
  40. Any help will be greatly appreciated.
  41.